
#include "gcc_output_processor.hpp"
#include "string.hpp"

#include <iostream>

Forte::GccOutputProcessor::GccOutputProcessor(CompilerOutputListener& listener)
  : mListener(listener)
{}

void Forte::GccOutputProcessor::OnExecutionOutput(char const* line, std::size_t length)
{
  std::vector<SimpleString> split;
  SimpleString(line, length).Split(':', split);
  if (split.size() < 5 || split[1].StartsWith(" In ") || split[0].StartsWith("In "))
    return;
  printf("4: %.*s\n", split[4].GetLength(), split[4].GetData());
  std::string const filename(split[0].ToString());
  unsigned const linenum(atoi(split[1].ToString().c_str()));
  if (split[3] == " error")
    mListener.OnError(split[4].ToString(), filename, linenum);
  else if (split[3] == " warning")
    mListener.OnWarning(split[4].ToString(), filename, linenum);
}

